#include "helpwin.h"
#include "ui_helpwin.h"

helpWin::helpWin(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::helpWin)
{
    ui->setupUi(this);

#ifndef DESK_TOP_RUN   // 背景填充，窗口框，和窗口的弹性设置，这里在机器里实现，桌面不需要  lbs-2017/4/26
    setAutoFillBackground(false);
    setWindowFlags(Qt::FramelessWindowHint);
    setAttribute(Qt::WA_TranslucentBackground,true);
#endif


#ifndef DESK_TOP_RUN
    ui->label_title->setStyleSheet( "background-color: rgb(0,150,255,200);font:bold 44pt" );
    ui->label_text->setStyleSheet( "background-color: rgb(255,204,64,220);;font:bold 44pt" );
    ui->label_message->setStyleSheet( "background-color: rgb(255,204,64,220);;font:bold 44pt" );
#else
    ui->label_title->setStyleSheet( "background-color: rgb(0,150,255,200);font:bold 5pt" );
    ui->label_text->setStyleSheet( "background-color: rgb(255,204,64,220);;font:bold 5pt" );
    ui->label_message->setStyleSheet( "background-color: rgb(255,204,64,220);;font:bold 5pt" );
#endif

    my_currentPage = 0;
    my_opPage = 7;
    my_mgPage =0;
    ui->widget_message->hide();
}

helpWin::~helpWin()
{
    delete ui;

}

void helpWin::showWin(GUIDETUPE type)
{
#ifndef DESK_TOP_RUN
    //设置全屏
    this->showFullScreen();
#endif
    this->show();


    my_currentType = type;
    ui->line_5->hide();

    ui->label_bmp->show();
    ui->label_page->show();

    ui->widget_message->hide();
    ui->line_6->hide();

    switch( type ){
    case GUID_OPERATION:
        my_currentPage = 1;
        my_pageNumber = my_opPage;
        this->showOperationGuid();
        break;
    case GUID_MAINTAIN:
        my_currentPage = 1;
        my_pageNumber = my_mgPage;
        this->showMaintainGuid();
        break;
    case GUID_PROPAGANDA:
        //this->playPropagandaVideo();
        break;
    default:
        break;
    }
}

void helpWin::setMessage(QString t_title, QString t_text)
{
    ui->label_bmp->hide();
    ui->label_page->hide();
    ui->widget_message->show();
    ui->label_title->setText(t_title);
    ui->label_text->setText( t_text);
      ui->line_5->hide();
      ui->line_6->hide();
      ui->label_message->hide();
       ui->label_button->hide();
    this->show();

}

void helpWin::setLanguage(LANGUAGE type)
{

}

void helpWin::showOperationGuid()
{
    QString pixmapPath = GUIDEIMAGE_ZH + "op_"+ QString().setNum(my_currentPage) + ".jpg";
    ui->label_bmp->setPixmap(pixmapPath);
    this->setCurrentPage();
}

void helpWin::showMaintainGuid()
{

    QString pixmapPath = GUIDEIMAGE_ZH + "mg_"+ QString().setNum(my_currentPage) + ".jpg";
    ui->label_bmp->setPixmap(pixmapPath);
    this->setCurrentPage();

}

void helpWin::playPropagandaVideo(QString path)
{

}

void helpWin::setCurrentPage()
{
    QString pageStr = QString().setNum(my_currentPage) + " / " + QString().setNum(my_pageNumber);
    ui->label_page->setText( pageStr );
}

void helpWin::keyPressEvent(QKeyEvent *ke)
{
    emit this->KeyPress();
    switch( ke->key() ){
    case Qt::Key_Left:   
        if( my_currentPage >1 ){
            my_currentPage--;
        }

        break;
    case Qt::Key_Right:
        if( my_currentPage < my_pageNumber ){
            my_currentPage++;
        }
        break;
    case Qt::Key_R:
        this->close();
        break;
    default:
        ke->ignore();
        break;
    }
    if ( my_currentType  == GUID_OPERATION) {
       showOperationGuid();
    }

    if ( my_currentType  == GUID_MAINTAIN){
        showMaintainGuid();
    }

}


void helpWin::setMessageList(QStringList list)
{
    ui->label_title->setText("x                     y");
    ui->label_text->setText( "x_result = " + list[0] + "\n"+ "x_diameter = " + list[1] +  "\n"
                            + "x_core = " + list[2] + "\n"+ "x_bobPoint = " + list[3] + "\n"
                            + "x_face_l = " + list[4] + "\n"+ "x_face_r = " + list[5] + "\n");

   ui->label_message->setText( "y_result = "+ list[6] + "\n"+ "y_diameter = "+ list[7] + "\n"
           + "y_core = "+ list[8] + "\n"+ "y_bobPoint = "+ list[9] + "\n"
           + "y_face_l = "+ list[10] + "\n"+ "y_face_r = "+ list[11] + "\n");

   ui->label_button->setText("端面角度::" + list[12] );
}

void helpWin::showmessages()
{

    ui->label_bmp->hide();
    ui->label_page->hide();
    ui->line_5->show();
    ui->line_6->show();
    ui->widget_message->show();
    ui->label_message->show();
    ui->label_button->show();
    this->show();
}




